package leetcode.秋招.荣耀;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/8/21 18:14
 * @description：
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String next = in.nextLine();
        int maxWidth = in.nextInt();
        String[] words = next.split(",");
        final String[] space = new String[maxWidth + 1];
        StringBuilder s = new StringBuilder();
        for (int i = 0; i <= maxWidth; i++) {
            space[i] = s.toString();
            s.append("*");
        }
        ArrayList<String> pWords = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            int curLen = words[i].length();
            int startI = i;
            while (i < words.length - 1 && curLen < maxWidth) {
                i++;
                curLen = curLen + words[i].length() + 1;
            }
            if (curLen > maxWidth) {
                curLen = curLen - words[i].length() - 1;
                i--;
            }
            pWords.add(processCurline(words, startI, i, curLen, maxWidth, space));
        }
        for (int i = 0; i < pWords.size(); i++) {
            System.out.println(pWords.get(i));
        }
    }

    private static String processCurline(String[] words, int si, int ei, int curLen, int maxWidth, String[] space) {
        StringBuilder sb = new StringBuilder();
        int map = ei - si;
        int addSpace = maxWidth - curLen + map;
        if (map == 0) {
            sb.append(words[ei]);
            sb.append(space[addSpace]);
            return sb.toString();
        }
        if (ei == words.length - 1) {
            for (int i = si; i < ei; i++) {
                sb.append(words[i]).append("*");
            }
            sb.append(words[ei]);
            sb.append(space[addSpace - map]);
            return sb.toString();
        }
        int allAddSpace = addSpace / map;
        int left = addSpace % map + si;
        for (int i = si; i < ei; i++) {
            sb.append(words[i]).append(space[allAddSpace]);
            if (i < left) sb.append("*");
        }
        sb.append(words[ei]);
        return sb.toString();
    }
}
